<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-navbar :fixed="false" :placeholder="true" title="备件审核列表" @leftClick="leftClick" bgColor="#0F53AC"
				leftIconColor="#fff">
			</u-navbar>
			<view class="listBot">
				<u-tabs :list="tabList" lineWidth="45" lineColor="#0F53AC" :activeStyle="activeStyle"
					:scrollable="false" :inactiveStyle="inactiveStyle" :itemStyle="itemStyle" @click="tabsClick"
					:current="current">
				</u-tabs>
			</view>
		</u-sticky>
		<view style="margin-top: 4rpx;" v-if="current==0">
			<view class="list-wrapper" v-for="(item,index) in verifyList" :key="index">
				<view class="list-info">
					<view class="list-title">
						<view class="title-left">
							备件申请单号:{{item.applyNum}}
							<view class="copy" @click="copyOrderNum(item.applyNum)">复制</view>
						</view>
						<!-- <view class="title-right"
						:class="[item.id==1?'title-ongoing':item.id==2?'title-dyz':item.id==3?'title-close':item.id==4?'title-finish':'']">
						{{item.id==2?'待维保':'维保中'}}</view> -->
					</view>
				</view>
				<view class="list-main">
					<view class="item-main">
						<view class="main-left" style="width: 100%;">
							<view class="txt1">工单信息</view>
							<view class="txt2">维修工单-{{item.orderNum}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">申请数量</view>
							<view class="txt2">{{item.applyAmount}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">申请人</view>
							<view class="txt2">{{item.applyUserName}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left" style="width: 100%;">
							<view class="txt1">申请时间</view>
							<view class="txt2">{{item.createTime}}</view>
						</view>
					</view>
				</view>
				<view class="item-btn" v-if="userId==item.dealUser" @click="toApproveChange(item)">
					<view class="ruku shenhe">去审核</view>
				</view>
				<view class="line8"></view>
			</view>
			<u-loadmore v-if="total>5" :status="status" :line="true" />
		</view>
		<view style="margin-top: 4rpx;" v-if="current==1">
			<view class="list-wrapper" v-for="(item,index) in verifyList" :key="index">
				<view class="list-info">
					<view class="list-title">
						<view class="title-left">
							备件申请单号:{{item.applyNum}}
							<view class="copy" @click="copyOrderNum(item.applyNum)">复制</view>
						</view>
						<!-- <view class="title-right"
						:class="[item.id==1?'title-ongoing':item.id==2?'title-dyz':item.id==3?'title-close':item.id==4?'title-finish':'']">
						{{item.id==2?'待维保':'维保中'}}</view> -->
					</view>
				</view>
				<view class="list-main">
					<view class="item-main">
						<view class="main-left" style="width: 100%;">
							<view class="txt1">工单信息</view>
							<view class="txt2">维修工单-{{item.orderNum}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">出库数量</view>
							<view class="txt2">{{item.totalAmount}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">备件总价值</view>
							<view class="txt2">{{item.applyFee}}元</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">审核人</view>
							<view class="txt2">{{item.dealUserName}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">审核时间</view>
							<view class="txt2">{{item.updateTime}}</view>
						</view>
					</view>
				</view>
				<view class="item-btn" @click="toSelectDetail(item)">
					<view class="ruku">查看详情</view>
				</view>
				<view class="line8"></view>
			</view>
			<u-loadmore v-if="total>5" :status="status" :line="true" />
		</view>
		<view class="empty-data" v-if="verifyList.length==0">
			<u-empty mode="data" :marginTop="100" text="暂无数据"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				activeStyle: {
					color: '#0F53AC',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				},
				inactiveStyle: {
					color: '#8c8c8c',
					transform: 'scale(1)'
				},
				itemStyle: {
					paddingLeft: '30rpx',
					paddingRight: '30rpx',
					paddingTop: '24rpx',
					paddingBottom: '24rpx',
					height: '48rpx'
				},
				current: 0,
				tabList: [{
						name: '待审核',
					},
					{
						name: '已审核',
					}
				],
				weixiugdList: [{
					id: 1
				}, {
					id: 2
				}, {
					id: 3
				}, {
					id: 4
				}],
				params: {
					approveStatus: 1, //审核状态；0.待提交  1.待审核    2.已审核
					pn: 1,
					ps: 5,
					keyword: ''
				},
				pages: 1,
				total: 0,
				verifyList: [],
				userId: uni.getStorageSync('userInfo').userId,
			}
		},
		onLoad(options) {
			if (options && options.currentId) {
				this.current = options.currentId - 0;
				this.verifyList = [];
				this.params.pn = 1;
				this.params.approveStatus = 2;
			}
			this.getList();
		},
		onPullDownRefresh() {
			if (this.current == 0) {
				this.verifyList = [];
				this.params.pn = 1;
				this.params.approveStatus = 1;
				this.getList();
			}
			if (this.current == 1) {
				this.verifyList = [];
				this.params.pn = 1;
				this.params.approveStatus = 2;
				this.getList();
			}
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 400)
		},

		methods: {
			//点击返回按钮
			leftClick() {
				uni.switchTab({
					url: '/pages/work/index'
				})
			},
			tabsClick(e) {
				this.current = e.index
				if (this.current == 0) {
					this.verifyList = [];
					this.params.pn = 1;
					this.params.approveStatus = 1;
					this.getList();
				}
				if (this.current == 1) {
					this.verifyList = [];
					this.params.pn = 1;
					this.params.approveStatus = 2;
					this.getList();
				}
			},
			toApproveChange(item) {
				console.log(item, 'item')
				uni.navigateTo({
					url: '/pages/subPackagesB/bjverify/approveInfo?id=' + item.id
				})
			},
			toSelectDetail(item) {
				uni.navigateTo({
					url: '/pages/subPackagesB/bjverify/spdetail?id=' + item.id
				})
			},
			getList() {
				uni.$u.http.post(`/device/mobile/devicePartApply/appPageList`, this.params).then(res => {
					if (res.code == 0) {
						this.verifyList = this.verifyList.concat(res.data.records);
						this.pages = res.data.pages;
						this.total = res.data.total;
					}
				}).catch(err => {})
			},
			copyOrderNum(data) {
				uni.setClipboardData({
					data: data,
					success: function() {
						console.log('success');
						uni.$u.toast('复制成功')
					}
				});
			}
		},
		onReachBottom() {
			if (this.params.pn >= this.pages) return;
			this.status = 'loading';
			this.params.pn = ++this.params.pn;
			setTimeout(() => {
				this.getList()
				if (this.params.pn >= this.pages) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		}
	}
</script>

<style lang="scss">
	page {

		background: #ffffff;

	}

	.list-wrapper {

		.list-info {
			// margin-top: 10rpx;
			background: #fff;
			padding: 32rpx;

			.list-title {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.title-left {
					display: flex;
					align-items: center;
					font-size: 30rpx;
					color: #000000;

					.copy {
						color: #A6A6A6;
						font-size: 10px;
						font-weight: 400;
						margin-left: 10rpx;
						border-radius: 8rpx;
						background: rgba(166, 166, 166, 0.3);
						padding: 8rpx 12rpx;
					}
				}

				.title-right {
					width: 96rpx;
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;
					border-radius: 8rpx;
					font-size: 24rpx;
				}

				.title-ongoing {
					color: #0F53AC;
					background-color: rgba(2, 173, 130, 0.3);
				}

				.title-dyz {
					color: #1962e0;
					background-color: rgba(27, 114, 252, 0.3);
				}

				.title-close {
					color: #fc770a;
					background-color: rgba(255, 120, 10, 0.3);
				}

				.title-finish {
					color: #00bf56;
					background-color: rgba(0, 238, 107, 0.3);
				}
			}

		}

		.list-main {
			padding: 4rpx 10rpx 20rpx 10rpx;
			background: #fff;
			border-top: 1px solid #f2f2f2;
			border-bottom: 1px solid #f2f2f2;

			.item-main {
				display: flex;
				justify-content: space-between;
				padding: 4rpx 30rpx;

				.main-left {
					width: 50%;
					text-align: left;

					.txt1 {
						color: #8c8c8c;
						font-size: 15px;
						font-weight: 400;
						padding: 10rpx 0;
					}

					.txt2 {
						color: #4d4d4d;
						font-size: 16px;
						font-weight: 400;
					}
				}
			}

			.gz-desc {
				padding: 15rpx 30rpx;

				.title {
					font-size: 28rpx;
					color: #8c8c8c;
				}

				.desc-reason {
					font-size: 28rpx;
					color: #2b2b2b;
					margin-top: 15rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
		}

		.item-btn {
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 24rpx 0;
			background: #fff;
			border-bottom: 1px solid #EDEDED;

			.chuku {
				width: 45%;
				font-size: 34rpx;
				color: #8c8c8c;
				text-align: center;
			}

			.ruku {
				width: 45%;
				font-size: 34rpx;
				color: #0F53AC;
				text-align: center;
			}

			.shenhe {
				color: #0F53AC;
			}

			.su-line {
				width: 4rpx;
				height: 50rpx;
				background: #f2f2f2;
			}
		}
	}

	.u-empty .u-icon {
		z-index: -1;
	}

	.u-tabs__wrapper__nav__item {
		// padding: 0 !important;
		width: 50%;
	}
</style>